from django.db import models



class Channel(models.Model):
    name = models.CharField(unique=True, blank=False, max_length=45)

    class Meta:
        db_table = 'Channels'

    def __unicode__(self):
        return u'%s' % (self.name)




class Show(models.Model):
    name = models.CharField(unique=False, blank=False, max_length=255)
    info = models.TextField(blank=True, null=True) 
    web = models.URLField(verify_exists=False, blank=True, null=True)

    class Meta:
        db_table = 'Shows'

    def __unicode__(self):
        return u'%s' % (self.name)

    def get_absolute_url(self):
        return self.web




class ShowTime(models.Model):
    show = models.ForeignKey('Show', unique_for_date='datetime')
    channel = models.ForeignKey('Channel')
    datetime = models.DateTimeField()

    class Meta:
        db_table = 'ShowTimes'

    def __unicode__(self):
        return u'%s at %s on %s' % (self.show, self.datetime.strftime('%H:%M %d-%m-%Y'), self.channel)

    def get_absolute_url(self):
        if self.show.web:
            return self.show.web
        else: return 'http://www.rtve.es/television/parrilla/parrilla_television.shtml'
